package com.example.dragcontentviewdemo.helper.internal.animationlistener;

import android.animation.Animator;

import com.example.dragcontentviewdemo.helper.internal.connector.AttachInfo;

/**
 * 拖拽视图的动画监听器，传入type与AttachInfo，绑定至特定上下文
 */
public class AnimationListenerImpl implements Animator.AnimatorListener {

    private AttachInfo mAttachInfo;
    private boolean mOutOfBound = false;

    public AnimationListenerImpl(boolean typeIsMoveOutOfBound, AttachInfo info) {
        mAttachInfo = info;
        mOutOfBound = typeIsMoveOutOfBound;
    }

    @Override
    public void onAnimationStart(Animator animation) {
        mAttachInfo.mAnimating = true;
    }

    @Override
    public void onAnimationEnd(Animator animation) {
        mAttachInfo.mAnimating = false;
        mAttachInfo.mVelocityTracker.clear(); //清空速度打点记录
        if (mOutOfBound && mAttachInfo.callback != null) {
            mAttachInfo.callback.onMoveOutOfBound();
            mAttachInfo.mIsViewHiddenNow = true;
        }
        else {
            mAttachInfo.mIsViewHiddenNow = false; //滑出显示
        }

    }

    @Override
    public void onAnimationCancel(Animator animation) {
        mAttachInfo.mAnimating = false;
    }

    @Override
    public void onAnimationRepeat(Animator animation) {

    }
}
